#include "CHealthBar.h"


CHealthBar::CHealthBar()
{

}

CHealthBar::~CHealthBar()
{

}

CHealthBar* CHealthBar::GetInstance()
{
	static CHealthBar instance;
	return &instance;
}

void CHealthBar::Render(CUnit* pUnit)
{
	float fPercent;
	m_rDrawRect.left = (LONG)(pUnit->GetDrawRect().left);
	if(pUnit->GetCurrHP() == pUnit->GetMaxHP())
		fPercent = 1;
	else
		fPercent = ((pUnit->GetCurrHP()%pUnit->GetMaxHP())*(100/(float)(pUnit->GetMaxHP()))) * 0.01f;
	int nRight = m_rDrawRect.left + 20;
	int length = (int)Lerp(
		(float)m_rDrawRect.left, (float)nRight, fPercent);
	m_rDrawRect.right = (LONG)( length);
	m_rDrawRect.top = (LONG)pUnit->GetDrawRect().top - 10;
	m_rDrawRect.bottom = (LONG)(
		m_rDrawRect.top + 5);

	//////////////////////////////////////////////////////////////
	//	Render
	CSGD_Direct3D::GetInstance()->SpriteEnd();
	//	Health Bar
	CSGD_Direct3D::GetInstance()->DrawRect(
		m_rDrawRect, 255,0,0);
	//  Health Bar Outline
	CSGD_Direct3D::GetInstance()->DrawLine(
		m_rDrawRect.left, m_rDrawRect.top, 
		nRight, m_rDrawRect.top, 0,0,0);
	CSGD_Direct3D::GetInstance()->DrawLine(
		nRight, m_rDrawRect.top, 
		nRight, m_rDrawRect.bottom, 0,0,0);
	CSGD_Direct3D::GetInstance()->DrawLine(
		nRight, m_rDrawRect.bottom, 
		m_rDrawRect.left, m_rDrawRect.bottom, 0,0,0);
	CSGD_Direct3D::GetInstance()->DrawLine(
		m_rDrawRect.left, m_rDrawRect.bottom, 
		m_rDrawRect.left, m_rDrawRect.top, 0,0,0);
	CSGD_Direct3D::GetInstance()->SpriteBegin();
	//
	//////////////////////////////////////////////////////////////
}

void CHealthBar::Render(CPlayer* pUnit)
{
	float fPercent;
	m_rDrawRect.left = (LONG)(pUnit->GetDrawRect().left);
	if(pUnit->GetCurrHP() == pUnit->GetMaxHP())
		fPercent = 1;
	else
		fPercent = ((pUnit->GetCurrHP()%pUnit->GetMaxHP())*(100/(float)(pUnit->GetMaxHP()))) * 0.01f;
	int nRight = m_rDrawRect.left + 20;
	int length = (int)Lerp(
		(float)m_rDrawRect.left, (float)nRight, fPercent);
	m_rDrawRect.right = (LONG)( length);
	m_rDrawRect.top = (LONG)pUnit->GetDrawRect().top - 5;
	m_rDrawRect.bottom = (LONG)(
		m_rDrawRect.top + 5);

	//////////////////////////////////////////////////////////////
	//	Render
	CSGD_Direct3D::GetInstance()->SpriteEnd();
	//	Health Bar
	CSGD_Direct3D::GetInstance()->DrawRect(m_rDrawRect, 255,0,0);
	//  Health Bar Outline
	CSGD_Direct3D::GetInstance()->DrawLine(
		m_rDrawRect.left, m_rDrawRect.top, 
		nRight, m_rDrawRect.top, 0,0,0);
	CSGD_Direct3D::GetInstance()->DrawLine(
		nRight, m_rDrawRect.top, 
		nRight, m_rDrawRect.bottom, 0,0,0);
	CSGD_Direct3D::GetInstance()->DrawLine(
		nRight, m_rDrawRect.bottom, 
		m_rDrawRect.left, m_rDrawRect.bottom, 0,0,0);
	CSGD_Direct3D::GetInstance()->DrawLine(
		m_rDrawRect.left, m_rDrawRect.bottom, 
		m_rDrawRect.left, m_rDrawRect.top, 0,0,0);
	CSGD_Direct3D::GetInstance()->SpriteBegin();
	//
	//////////////////////////////////////////////////////////////
}